'''
主要用于将多个文件夹中的csv文件按照名称融合，并去除多余行
一级目录名称分别为1,2,3,4,5
二级目录名称分别为各站间的加速减速匀速等分类
每个二级目录内部包含13个传感器文件，格式是csv
最终生成json文件
'''
import os
import json


if __name__ == '__main__':
    # print('以下是所有文件')
    path = '/home/kyrie/master_paper/dataset/csvfile/'
    path1 = '/home/kyrie/master_paper/dataset/csvfile/1'

    # sensor_list中存储的是分类依据
    sensor_list = ['cegun', 'chilunxiang', 'dianjichui', 'dianjiheng', 'fuchen', 'hengjian', 'hengxiang', 'lingxing',
                   'niuzhuan', 'qianyin', 'zhidong', '角速度', '_速度']
    dict = {}
    for sensor in sensor_list:
        # print('以下是%s数据：' % sensor)
        temp_list = []
        for roots, dirs, files in os.walk(path):
            for ifile in files:
                tempfile = roots + '/' + ifile
                if tempfile.find(sensor) != -1:
                    temp_list.append(tempfile)
        # print(temp_list)
        temp_list.sort()
        dict[sensor] = temp_list
        # print(dict)
    print(dict['cegun'])
    alist = dict['cegun']
    alist.sort()
    print(alist)
    for item in alist:
        print(item)
    # json = json.dumps(dict,sort_keys=True,ensure_ascii=False)
    # print(json)
    with open('/home/kyrie/master_paper/dataset/file.json', 'w') as f:
        json.dump(dict, f,sort_keys=True,indent=4,separators=(',',':'),ensure_ascii=False)
